<?php
	error_reporting(7);
	ini_set('display_errors',1);
define('VERSION', 'Neutrino 0.8.7 Atomic Edition');
$_v = $_c = $hook = array();
$_v=$_GET+$_POST;
$_c=$_COOKIE;
$_s['data_dir']='data';
$_s['pages_dir']=$_s['data_dir'].'/pages';
$_s['posts_dir']=$_s['data_dir'].'/posts';
$_s['tags_dir']=$_s['data_dir'].'/tags';
$_s['tags_cache']=$_s['tags_dir'].'/cache64';
$_s['comments_dir']=$_s['data_dir'].'/comments';
$_s['ext_dir']='ext';
if (file_exists($_s['data_dir'].'/settings.php'))include_once $_s['data_dir'].'/settings.php';
else die('Сайт поврежден! Восстановите файл настроек '.$_s['data_dir'].'/settings.php. См. <a href="readme.txt">readme.txt</a>.');

$i_p=$_s['data_dir'].'/settings.ini.php';
if((!@$_s['tpl_patch']||!@$_s['lang_file'])){# Авто-обновление и авто-починка настроек
	$_i=@parse_ini_file($i_p);
	$_i['lang_file']=(@$_i['lang_file']&&is_file($_i['lang_file']))?$_i['lang_file']:'lang/ru.php';
	$_i['tpl_patch']=(@$_i['tpl_patch']&&is_dir($_i['tpl_patch']))?$_i['tpl_patch']:'tpl/default';
	$s=$_s['data_dir'].'/settings.php';
	$settings=file_get_contents($s);str_replace('?>','',$settings);
	file_put_contents($s,$settings.'$_s[\'tpl_patch\']=\''.$_i['tpl_patch'].'\';$_s[\'lang_file\']=\''.$_i['lang_file'].'\';');
	$_s['lang_file']=$_i['lang_file'];$_s['tpl_pacth']=$_i['tpl_pacth'];
}if(is_file($i_p))unlink($i_p);unset($i_p);

$_i['lang_file']=$_s['lang_file'];$_i['tpl_patch']=$_s['tpl_patch'];#Строчка для обратной совместимости


@include $_s['data_dir'].'/sess.php';
if (@$_c['sid'] && $_c['sid'] == @$_s['sid']){
	define('ADMIN',1);
	error_reporting(7);
	ini_set('display_errors',1);
}
else {
	define('ADMIN',0);
	ini_set('display_errors',0);
}

include "lib/functions.php";

if(@$_v['r']){
	$_r=explode('/',@$_v['r']);
	reset($_r);$a=0;foreach($_r as $r){if($a){$value=$r;$a--;} else { $name=$r; $a++; } if(@$name&&@$value)$_v[$name]=$value;}
}
	if(@$_v['p'])$_v['p']=intval($_v['p']);
	if(@$_v['pg'])$_v['pg']=str_replace('/','',$_v['pg']);

#Регионы
$_t=array('null'=>'','headers'=>'','closure'=>'','left'=>'','right'=>'','head'=>'','footer'=>'',
'ptup'=>'','ptdw'=>'','ptfup'=>'','ptfdw'=>'','cmtfup'=>'','cmtfdw'=>'','cmtup'=>'','cmtdw');
extract($_t, EXTR_REFS);# Создаем ссылки - отдельные переменные
include $_i['lang_file'];//"lang/ru.php";
include "ext/index.php";

header('Content-type: text/html; charset=UTF-8');
$title=@$_s['blogname'];
$pages_link=$cmnt['del']="";

if (get_magic_quotes_gpc()) $_v=array_map('stripslashes',$_v);

if (is_numeric(@$_v['p']) && @$_s['seo'])
{
	$post = post_info($_v['p']);
	$title=$subj=empty($post['title'])?substr(strip_tags($post['text']),0,$_s['seo']):$post['title'];
	$poy=1;
}

if(@$_v['action']!='rss'&&@$_v['action']!='login')include $_s['tpl_patch'].'/head.html';//Это временное решение!

if(@$_v['action'])include 'lib/actions.php';
else {
	if (@$_v['pg']) echo nae_page($_v['pg']);
	elseif(isset($_v['ext'])){
		$ext=trim($_v['ext']);
		if($ext_ini[$ext]==1) include 'ext/'.$ext.'/'.$ext.'.php';
	}
	else {
	
		if (is_numeric(@$_v['p'])) echo nae_post($_v['p']).nae_comments_list($_v['p']);
		else echo nae_posts_list(@$_v['t'], @$_v['skip']);
	}
}
nae_exit();
?>
